package com.example.freshmenclient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.widget.RadioGroup;

import com.example.freshmenclient.fragments.AnouncenMentsFragment;
import com.example.freshmenclient.fragments.ClassMateFragment;
import com.example.freshmenclient.fragments.LeaveWordFragment;
import com.example.freshmenclient.fragments.MeFragment;
import com.example.freshmenclient.fragments.NewsFragment;
import com.example.freshmenclient.util.FragmentUtil;

public class MainActivity extends AppCompatActivity {

    private RadioGroup rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
    }

    private void initEvent() {
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_classmate:
                        FragmentUtil.registerFragment(getSupportFragmentManager(), new ClassMateFragment());
                        break;
                    case R.id.rb_leave_message:
                        FragmentUtil.registerFragment(getSupportFragmentManager(), new LeaveWordFragment());
                        break;
                    case R.id.rb_news:
                        FragmentUtil.registerFragment(getSupportFragmentManager(), new NewsFragment());
                        break;
                    case R.id.rb_announcement:
                        FragmentUtil.registerFragment(getSupportFragmentManager(), new AnouncenMentsFragment());
                        break;
                    case R.id.rb_my:
                        FragmentUtil.registerFragment(getSupportFragmentManager(), new MeFragment());
                        break;
                }
            }
        });
    }

    private void initView() {
        rg = findViewById(R.id.rg_nav);
    }
}
